package vip.xiaonuo.bi.modular.dataset.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.bi.modular.dataset.service.DatasetService;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 数据源分类表控制器
 *
 * @author 顾育司
 * @date  2023/12/15 12:09
 */
@Api(tags = "数据集-文件相关")
@ApiSupport(author = "SNOWY_TEAM", order = 1)
@RestController
@Validated
public class DataSetController {
    @Resource
    DatasetService datasetService;

    /**
     * 获取数据源分类表类型
     */
    @SneakyThrows
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", required = true, value = "上传文件参数"),
            @ApiImplicitParam(name = "type", value = "两种文件类型： file_csv或file_excel"),
            @ApiImplicitParam(name = "charset",defaultValue ="GBK" ,value = "file为file_csv才有。解析文件数编码设置默认GB18030 可选GBK, UTF-8, UTF-16,"),
    })
    @ApiOperation("导入-文件数据集:excel/csv")
//    @SaCheckPermission("/bi/classify/page")
    @PostMapping("/bi/dataset/uploud")
    public CommonResult upload(@RequestPart(value = "file")MultipartFile file,String type, String charset,String colInfoJson) throws Exception{
        return CommonResult.data(datasetService.upload(file,type,charset,colInfoJson));
    }





    @SneakyThrows
    @ApiOperationSupport(order = 1)
    @ApiOperation("导出文件")
//    @SaCheckPermission("/bi/classify/page")
    @GetMapping("/bi/dataset/exportFile")
    public CommonResult exportFile(HttpServletResponse response,Long id) throws Exception{
        datasetService.exportFile(response,id);
        return CommonResult.ok();
    }


}